package com.ymttest.business.service;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

import com.ymatou.iapi.openapibiz.parameter.AuthorizeBean;
import com.ymatou.iapi.openapibiz.parameter.CancelAuthBean;
import com.ymatou.iapi.openapibiz.parameter.NewThirdPartyAppBean;
import com.ymatou.iapi.openapibiz.service.AuthorizeCall;
import com.ymatou.iapi.openapibiz.service.CancelAuthCall;
import com.ymatou.iapi.openapibiz.service.NewThirdPartyAppCall;
import com.ymttest.utils.TestDataManager;

public class OpenApiBizCallService {
	
	/// 创建第三方应用app
	public NewThirdPartyAppBean createNewThirdPartyAppBean()
	{
		NewThirdPartyAppBean newThirdPartyAppBean = new NewThirdPartyAppBean();
		newThirdPartyAppBean.setAppName("第三方应用"+TestDataManager.getRandomNum(5));
		newThirdPartyAppBean.setAppDesc("dscjjkjjkk");
		return newThirdPartyAppBean;
	}
	
	public NewThirdPartyAppCall newthirdpartyappCall(NewThirdPartyAppBean newThirdPartyAppBean) throws ClientProtocolException, IOException
	{
		NewThirdPartyAppCall newThirdPartyAppCall = new NewThirdPartyAppCall();
		
		newThirdPartyAppCall.setData(newThirdPartyAppBean);
		newThirdPartyAppCall.callService();			
	
		return newThirdPartyAppCall;
	}
	
	///授权： 卖手给应用授权
	public AuthorizeBean createAuthorizeBean_USER_DEV()
	{
		AuthorizeBean authorizeBean = new AuthorizeBean();
		
		String appName="auto_USER_DEV_"+TestDataManager.getRandomIntNum(6);
		   
		authorizeBean.setSellerId(TestDataManager.getRandomIntNum(6));
		authorizeBean.setAppName(appName);
		authorizeBean.setType("USER_DEV");
		authorizeBean.setAppDesc("APP_Desc "+TestDataManager.getRandomIntNum(10));

		return authorizeBean;
	}
	
	public AuthorizeBean createAuthorizeBean_THIRD_PARTY(String appId)
	{
		AuthorizeBean authorizeBean = new AuthorizeBean();
		
		Integer userId=	TestDataManager.getRandomIntNum(5);
		   
		authorizeBean.setSellerId(userId);
		authorizeBean.setAppId(appId);
		authorizeBean.setType("THIRD_PARTY");
		authorizeBean.setAppDesc("APP_Desc "+TestDataManager.getRandomIntNum(10));

		return authorizeBean;
	}
	
	public AuthorizeCall authorizeCall(AuthorizeBean authorizeBean) throws ClientProtocolException, IOException
	{
		AuthorizeCall authorizeCall = new AuthorizeCall();
		
		authorizeCall.setData(authorizeBean);
		authorizeCall.callService();		
		
		return authorizeCall;
	}
	
	//取消授权
	public CancelAuthBean createCancelAuthBean(Integer sellerId, String authCode, String appId)
	{
		CancelAuthBean cancelAuthBean = new CancelAuthBean();
		
		cancelAuthBean.setSellerId(sellerId);
		cancelAuthBean.setAuthCode(authCode);
		cancelAuthBean.setAppId(appId);
		
		return cancelAuthBean;
	}
	
	public CancelAuthCall cancelAuth(CancelAuthBean cancelAuthBean) throws ClientProtocolException, IOException
	{
		CancelAuthCall cancelAuthCall = new CancelAuthCall();
		
		cancelAuthCall.setData(cancelAuthBean);
		cancelAuthCall.callService();
		
		return cancelAuthCall;
	}
	
	public static void main(String[] args) {
		try {
			OpenApiBizCallService OpenApiBizCallService = new OpenApiBizCallService();
			
			AuthorizeBean authorizeBean = OpenApiBizCallService.createAuthorizeBean_USER_DEV();
			authorizeBean.setSellerId(288484);
			AuthorizeCall authorizeCall = OpenApiBizCallService.authorizeCall(authorizeBean);

			
//			OpenApiBizCallService OpenApiBizCallService = new OpenApiBizCallService();
//			
//			NewThirdPartyAppBean newThirdPartyAppBean = OpenApiBizCallService.createNewThirdPartyAppBean();
//			NewThirdPartyAppCall newThirdPartyAppCall = OpenApiBizCallService.newthirdpartyappCall(newThirdPartyAppBean);
//	
//			AuthorizeBean authorizeBean = OpenApiBizCallService.createAuthorizeBean_THIRD_PARTY(newThirdPartyAppCall.getAppId());
//			authorizeBean.setSellerId(288484);
//			AuthorizeCall authorizeCall = OpenApiBizCallService.authorizeCall(authorizeBean);

		} catch (Exception e) {
			// TODO: handle exception
		}
	
	}
}
